package com.theobserver.theobserver;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.RequestPasswordResetCallback;

public class FgetPwdActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fgetpwd);


        Button bt=(Button)findViewById(R.id.btn_fgetpwd_ok) ;
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String email=((EditText)findViewById(R.id.Fget_Pwad_Mail)).getText().toString();

                if (email.length()!=0) {

                    AVUser.requestPasswordResetInBackground(email, new RequestPasswordResetCallback() {
                        @Override
                        public void done(AVException e) {
                            if (e == null) {
                                Toast.makeText(FgetPwdActivity.this, "请前往邮箱重置密码！", Toast.LENGTH_SHORT).show();
                                finish();
                            }else if (e.getCode()==205){
                                Toast.makeText(FgetPwdActivity.this, "该邮箱账号并未注册！", Toast.LENGTH_SHORT).show();
                            }
                            else {
                                Toast.makeText(FgetPwdActivity.this,   e.toString(), Toast.LENGTH_SHORT).show();

                        }
                        }
                    });
                }else
                    Toast.makeText(FgetPwdActivity.this, "请输入邮箱账号！", Toast.LENGTH_SHORT).show();
            }
        });

        //返回按钮
        TextView Tv=(TextView)findViewById(R.id.tv_fgetpwd_reten);
        Tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
